package com.cn.controller;

import com.cn.bean.Goods;
import com.cn.util.JDBCUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class Select {
    public static Object[][] getGoods(String sql) {

        ResultSet resultSet = JDBCUtils.query(sql);
        ArrayList<Goods> list=new ArrayList<Goods>();
        try {
            while (resultSet.next()) {
                Goods goods=new Goods();
                goods.setGoodsID(resultSet.getInt(1));
                goods.setGoodsName(resultSet.getString(2));
                goods.setGoodsCount(resultSet.getInt(3));
                goods.setGoodsPrice(resultSet.getString(4));
                goods.setGoodsImg(resultSet.getString(5));
                list.add(goods);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Object[][] objects=new Object[list.size()][5];
        for(int i=0;i<list.size();i++) {
            objects[i][0]=list.get(i).getGoodsID();
            objects[i][1]=list.get(i).getGoodsName();
            objects[i][2]=list.get(i).getGoodsCount();
            objects[i][3]=list.get(i).getGoodsPrice();
            objects[i][4]=list.get(i).getGoodsImg();
        }
        return objects;
    }

}